/********************************************************************************
 *@description: 抽奖参与用户详情
 *@author: Xhd
 *@API: 王清悦
 *@date: 2024-01-19 16:17:23
 *@version: V1.0.0
**********************************************************************************/

import React, { Component } from 'react';
import { apiGetParticipatingUserPage, apiGetWinningRecordsPage, apiGetUserBlockRecords } from "@/request/lotteryTools";
import ThePagination from '@/components/ThePagination';
import { apiGetUserDetails } from '@/request/users';
import TheTable from '@/components/TheTable';
import GoBack from "@/components/TheGoBack";
import { Descriptions, Modal } from 'antd';

class Name extends Component {
  constructor(props) {
    super(props)
    this.queryFormRef = React.createRef();
    this.state = {
      memberId: this.props.match.params.id,
      bloColumns: [
        {
          title: "封禁类型",
          dataIndex: "banType",
          key: "banType",
        },
        {
          title: "封禁原因",
          dataIndex: "banReason",
          key: "banReason",
        },
        {
          title: "封禁时间",
          dataIndex: "createTime",
          key: "createTime",
        },
        {
          title: "解封时间",
          dataIndex: "updateTime",
          key: "updateTime",
        },
        {
          title: "解封原因",
          dataIndex: "unsealingReason",
          key: "unsealingReason",
        },
      ],
      winColumns: [
        {
          title: "中奖时间",
          dataIndex: "winningTime",
          key: "winningTime",
        },
        {
          title: "活动名称",
          dataIndex: "turntableName",
          key: "turntableName",
        },
        {
          title: "奖品名称",
          dataIndex: "prizeName",
          key: "prizeName",
        },
        {
          title: "奖品数量",
          dataIndex: "prizeCount",
          key: "prizeCount",
        },
        {
          title: "奖品等级",
          dataIndex: "prizeLevel",
          key: "prizeLevel",
          render: (text) => {
            let label = ""
            switch (parseInt(text)) {
              case 1:
                label = "一等奖"
                break;
              case 2:
                label = "二等奖"
                break;
              case 3:
                label = "三等奖"
                break;
              case 4:
                label = "四等奖"
                break;
              case 5:
                label = "五等奖"
                break;
              case 6:
                label = "六等奖"
                break;
              default:
                break;
            }
            return label
          }
        },
      ],
      winDataSource: [],
      bloDataSource: [],
      pageData: { pageNo: 1, pageSize: 10 },
      total: 0,
      searchValue: {},
      searchOption: [],
      data: ""
    }
  }
  async componentDidMount() {
    const { memberId } = this.state
    await apiGetParticipatingUserPage({ memberId, pageNo: 1, pageSize: 1 }).then(res => {
      if (res.code === 0) {
        var reg = /^(\d{3})\d{4}(\d{4})$/;
        res.data[0].memberMobile = res.data[0].memberMobile ? res.data[0].memberMobile.toString().replace(reg, '$1****$2') : ""
        this.setState({
          data: res.data[0]
        })
      }
    })
    this.getBlockRecords()
    this.getWinningRecord()
  }
  getBlockRecords = async () => {
    const { memberId } = this.state
    await apiGetUserBlockRecords({ memberId }).then(res => {
      if (res.code === 0) {
        this.setState({
          bloDataSource: res.data
        })
      }
    })
  }
  getWinningRecord = async () => {
    const { memberId, pageData } = this.state
    await apiGetWinningRecordsPage({ memberId, ...pageData }).then(res => {
      if (res.code === 0) {
        let data = res.data.map(item=>{
          if(item.prizeType === "CB"){
            item.prizeCount = item.prizeCount / 10
          }
          return item
        })
        this.setState({
          winDataSource: data,
          total: res.totalCount
        })
      }
    })
  }
  pageChange = (pageNo, pageSize) => {
    this.setState({
      pageData: {
        pageNo,
        pageSize
      }
    }, () => this.getWinningRecord())
  }
  render() {
    const { data, winColumns, winDataSource, pageData: { pageNo, pageSize }, total, bloColumns, bloDataSource } = this.state;
    return (<div className='p-layout-box'>
      <GoBack history={this.props.history} title={"用户详情"} />
      <Descriptions title="基础资料" column={5} >
        <Descriptions.Item label="用户ID">{data.memberId}</Descriptions.Item>
        <Descriptions.Item label="用户昵称">{data.nickName}</Descriptions.Item>
        <Descriptions.Item label="手机号">{data.memberMobile}</Descriptions.Item>
        <Descriptions.Item label="状态">{data.state === 1 ? "正常" : "禁用"}</Descriptions.Item>
      </Descriptions>
      <div>封禁记录</div>
      <TheTable scroll={{ x: 'max-content', y: '30vh' }} columns={bloColumns} dataSource={bloDataSource} />
      <div>中奖记录</div>
      <TheTable scroll={{ x: 'max-content', y: '30vh' }} columns={winColumns} dataSource={winDataSource} />
      <ThePagination pageNo={pageNo} pageSize={pageSize} total={total} pageChange={this.pageChange} />

    </div>)
  }
}

export default Name